/*
 * redmicro all Copyright (c)
 */

Rsd.define('Rsd.Faith.admin.SysBuildDialog', {
    extend: 'Rsd.view.BaseListDialog',
    xtype:'sys-build',
    requires: [
        'Rsd.control.GridToolBarSimple',
        'Rsd.control.GridToolBar',
        'Rsd.control.PagingBar'
    ],
    width:1200,
    height:650,
    serviceName:'system.getapilist',
    toolBar:{
        xtype:'grid-tool-bar-simple',
        items:[
            {xtype:'text',label:'密码',width:250,textChanged:'pwd_changed'},
            {xtype:'checkbox',width:180,margin:'0 0 0 30',label:{text:'清楚历史任务',position:'right',style:{lineHeight:25}},textChanged:'rebuild_changed'},
            {xtype:'button',width:150,text:'生成定时任务',handler:'btn_build_api'}
            ]
    },
    footBar:{xtype:'paging-bar',indexChanged:'pageIndexChanged'},
    gridColumns: [
        {
            "text": "序号",
            "xtype": "index",
            "width": 20,
            "index": 0
        },
        {
            "name": "Text",
            "text": "描述",
            "sortable": false,
            "index": 0,
            "xtype": "string",
            "width": 50
        },
        {
            "name": "Url",
            "text": "Url",
            "sortable": false,
            "index": 0,
            "xtype": "string",
            "width": 200
        },
        {
            "name": "Enabled",
            "text": "已启动",
            "sortable": false,
            "index": 0,
            "xtype": "string",
            "width": 30
        },
        {
            "name": "Success",
            "text": "成功",
            "sortable": false,
            "index": 0,
            "xtype": "string",
            "width": 30
        },
        {
            "name": "Respone",
            "text": "返回结果",
            "sortable": false,
            "index": 0,
            "xtype": "string",
            "width": 50,
            nobr:true
        }
    ],

    /*
    * */
    constructor: function (config) {
        var me = this;
        config = config || {};
        Rsd.apply(this, config);

        var me = this;

        me.dataStore = Rsd.app.getService(me.serviceName);
    },
    load:function load() {
       // console.log(this.group);
       this.callParent({group:this.group});
    },
    /**
     * @description 获取分页信息,在查询时，自动加上分页信息
     * */
    getPagingOpt:function getPagingOpt() {
        if(this.items[0].footBar instanceof  Rsd.control.PagingBar)
        {
            return this.items[0].footBar.getPaging();
        }
        return {};
    },

    /**
     * @description 设置分页信息,一般在查询条件发发生改变时，需重新设置分页 {pageIndex: 0}
     * */
    setPagingOpt:function setPagingOpt(opt) {

        if(this.items[0].footBar instanceof  Rsd.control.PagingBar)
        {
            return this.items[0].footBar.setPaging(opt);
        }
    },
    /*
    * */
    pageIndexChanged: function pageIndexChanged(pagingOpt) {
        //debugger;

        this.load({});//只需重新加载，pagingOpt 信息自动获取

    },
    pwd_changed:function (sender,e) {
        this.pwd = sender.getValue();
    },
    rebuild_changed:function(sender,e)
    {
        this.rebuild = sender.isChecked();
    },
    /*
    * */
    btn_build_api:function () {
        var me = this;
        var id = Rsd.showWaiting('正在生成数据...');
        Rsd.app.getService('Admin.Rebuild').requestJson({group:this.group,rebuild:this.rebuild,pwd:this.pwd},function (data) {
           console.log(data);
           if(data.success)
           {
               me.load();
           }
            Rsd.closeWaiting(id);
        });
    }

});
